package com.bwhx.eruler.service.casdilly.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.casdilly.CasdillyCustomer;
import com.bwhx.eruler.bean.casdilly.Contract;
import com.bwhx.eruler.bean.casdilly.FenchangStatus;
import com.bwhx.eruler.bean.casdilly.Linkman;
import com.bwhx.eruler.dao.casdilly.CasdillyCustomerDAO;
import com.bwhx.eruler.dao.casdilly.LinkmanDAO;
import com.bwhx.eruler.service.casdilly.LinkmanService;
import com.bwhx.eruler.util.ListUtils;
@Service
public class LinkmanServiceImpl implements LinkmanService {
	
	@Autowired
	LinkmanDAO  linkmanDAO;
	
	@Autowired
	CasdillyCustomerDAO casdillyCustomerDAO;
	
	 
	@Override
	public List<Linkman> findByContractSerial(String cPIDSerial) {
		
		return linkmanDAO.findByContractSerial(cPIDSerial);
	}

	@Override
	public void insert(Linkman lm) {
		linkmanDAO.insert(lm);
		
	}

	@Override
	public void update(Linkman lm) {
		linkmanDAO.update(lm);
		
	}

	@Override
	public List<Linkman> list(Page p) {
		return linkmanDAO.list(p);
	}

	@Override
	public Integer count(Linkman linkman) {
		return linkmanDAO.count(linkman);
	}

	@Transactional
	@Override
	public void delete(Linkman lm) {
		Date date = new Date();
		
		lm.setModifyTime(date);
		linkmanDAO.delete(lm);
		
	/*	CasdillyCustomer casdillyCustomer = new CasdillyCustomer();
 		casdillyCustomer.setContractID(lm.getlMIDFenChang()); 
 		casdillyCustomer.setModifyTime(date);
 		casdillyCustomer.setModifierID(lm.getModifierID());
 		
 		
		casdillyCustomerDAO.delete(casdillyCustomer);*/
		
		//删除scandata
		List<Linkman> linkManList = new ArrayList<Linkman>();
		linkManList.add(lm);
		List<CasdillyCustomer> ccustomerList = casdillyCustomerDAO.listByLinkmanList(linkManList);
		if(ListUtils.isSubstantial(ccustomerList)){
			casdillyCustomerDAO.updateDelFlagByCcustomerList(ccustomerList);
			casdillyCustomerDAO.updateScanDataDelFlagByCcustomerList(ccustomerList);
		}
			 
		
		
	}

	@Override
	public List<Linkman> findByContractSerialAndCreatorID(String cPIDSerial, String creatorID, Integer start) {
		return linkmanDAO.findByContractSerialAndCreatorID(cPIDSerial,creatorID,start);
	}

	@Override
	public List<FenchangStatus> linkmanStatusList(Page p) {
 		return linkmanDAO.linkmanStatusList(p);
	}

	@Override
	public Integer linkmanStatusCount(Linkman linkman) {
 		return linkmanDAO.linkmanStatusCount(linkman);
	}

	 

	@Override
	public List<Linkman> findByNameAndContractSerial(Linkman lm) {
		return linkmanDAO.findByNameAndContractSerial(lm);
	}

	@Override
	@Transactional
	public void updateDelFlagByContract(Contract contract) {
		linkmanDAO.updateDelFlagByContract(contract);
 		
	}

	


}
